package com.rsa.test;

import org.junit.Test;

import java.util.Base64;

public class Base64Util {


    @Test
    public void test() {

        try {

            // 原始字符串
            String initChars = "abc!@64编解码#-Adv://";

            // 基础编码
            String b64En = Base64.getEncoder().encodeToString(initChars.getBytes("utf-8"));
            // 基础解码
            byte[] b64De = Base64.getDecoder().decode(b64En);
            String deChars = new String(b64De, "utf-8");

            // Url编码
            String b64UrlEn = Base64.getUrlEncoder().encodeToString(initChars.getBytes("utf-8"));
            // Url解码
            byte[] b64UrlDe = Base64.getUrlDecoder().decode(b64UrlEn);
            String urlDeChars = new String(b64UrlDe, "utf-8");

            // Mime编码
            String b64MimeEn = Base64.getMimeEncoder().encodeToString(initChars.getBytes("utf-8"));
            // Mime解码
            byte[] b64MimeDe = Base64.getMimeDecoder().decode(b64MimeEn);
            String mimeDeChars = new String(b64MimeDe, "utf-8");

            System.out.println(b64En);
            System.out.println(b64UrlEn);
            System.out.println(b64MimeEn);

        } catch (Exception ex) {

            ex.printStackTrace();

        }

    }

}
